﻿#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QLabel>
#include <QMenu>
#include <QRunnable>
#include <QThread>
#include <QTimer>
#include "process/objlocation0/objlocation0.h"
#include "process/objlocation1/objlocation1.h"
#include "process/objlocation2/objlocation2.h"
#include "process/objlocation3/objlocation3.h"
#include "data/datasaveread1.h"
#include "modbus1/widget.h"
#include "loaduser/loaddialog.h"
#include "balser1/balserform1.h"
#include "camsetting.h"
#include "objsetting.h"
#include "message.h"


class threadObj0;
class threadObj1;
class threadObj2;
class threadObj3;
class threadSendValue;
class MainWindow;

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    QString showCurTime();
    virtual void timerEvent(QTimerEvent *event);   //定时器处理连续运行操作
    virtual void closeEvent(QCloseEvent *event);
    void sendCoilsValue();

private slots:

    void doProDataSendPara(QString currentProjectName);   //处理data发送参数

    void doProCamSaveData(int schedule);    //处理obj1发送参数
    void doProObjMakeModelResult(bool);     //处理obj制作模板成功结果
    void doProDataSaveResult(bool);         //处理obj数据保存成功结果
    void doProCamResult(Hobject);  //处理cam0发送图片
    void doProLoadStatus(bool);

    void messageshow(const QString& msg);

    void on_btnLoad_clicked();      //登录按钮
    void on_btnProduct_clicked();   //产品按钮
    void on_btnConnect_clicked();   //连接服务按钮
    void on_btnRun_clicked();       //运行按钮
    void on_btnClear_clicked();     //清空按钮
    void on_btnReset_clicked();     //统计重置按钮
    void on_btnCam_clicked();
    void on_btnObj_clicked();

    void doProCoilsSendStart(int);

private:
    Ui::MainWindow *ui;

    //***************状态栏显示时间***********//
    int m_showTime;   //状态栏显示时间定时器
    int m_getCoilsValue;
    bool isRun = false;     //是否正在运行

    //***********项目参数************//
    QString m_curProjectName;        //当前工程名
    int m_projectSum;                //项目个数
    QList<QString> m_projectList;    //项目列表

    //************定位参数************//
    objlocation0 *obj0;       //定位0定位对象
    objlocation1 *obj1;       //定位1定位对象
    objlocation2 *obj2;       //定位2定位对象
    objlocation3 *obj3;       //定位3定位对象

    ObjPara m_objPara[CAMERA_NUMBER];  //定位1系统参数
    HTuple m_winId[CAMERA_NUMBER];   //定位1显示图像句柄
    HTuple m_WindowHandle[CAMERA_NUMBER];

    //************相机参数************//
    balserForm1 *cam[CAMERA_NUMBER];
    camPara m_camPara[CAMERA_NUMBER];  //相机1参数
//    bool camConStatus[CAMERA_NUMBER] = {false, false, false, false}; //相机连接状态 0为未连接，1为连接

    //************数据保存参数************//
    datasaveread1 *data;  //数据保存类

    //***************tcp通信*************//
    Widget *mod;

    //*************登陆对话框*************//
    loadDialog *load;
    bool m_isloaded = false;

    //*************数据统计*************//
    int m_totalNumber = 0;
    int m_okNumber = 0;
    int m_ngNumber = 0;

    //**************相机设置****************//
    camSetting *camset;
    objSetting *objset;

    //***************多线程参数***************//
    threadObj0 *r0;
    threadObj1 *r1;
    threadObj2 *r2;
    threadObj3 *r3;
    threadSendValue *r4;

};

class threadObj0 : public QRunnable
{
public:
    threadObj0();
    threadObj0(balserForm1 *cam, objlocation0 *obj);
    void run();
    balserForm1 *cam0;
    objlocation0 *obj0;
};

class threadObj1 : public QRunnable
{
public:
    threadObj1();
    threadObj1(balserForm1 *cam, objlocation1 *obj);
    void run();
    balserForm1 *cam1;
    objlocation1 *obj1;
};

class threadObj2 : public QRunnable
{
public:
    threadObj2();
    threadObj2(balserForm1 *cam, objlocation2 *obj);
    void run();
    balserForm1 *cam2;
    objlocation2 *obj2;
};

class threadObj3 : public QRunnable
{
public:
    threadObj3();
    threadObj3(balserForm1 *cam, objlocation3 *obj);
    void run();
    balserForm1 *cam3;
    objlocation3 *obj3;
};

class threadSendValue : public QRunnable
{
public:
    threadSendValue();
    threadSendValue(Widget *mod);
    void run();
    Widget *m_mod;
};
#endif // MAINWINDOW_H
